package com.alen.sun.dao;

import com.alen.sun.bean.Activity;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface ActivityMapper {
    //添加活动
    @Insert("INSERT INTO activity (activityId, activity_name, activity_description, activity_time, categoryId, activity_image) VALUES (#{activityId},#{activityName},#{activityDescription},#{activityTime},#{categoryId},#{activityImage})")
    Boolean addActivity(Activity activity);

    //修改活动
    @Update("UPDATE activity SET activity_name = #{activityName}, activity_description = #{activityDescription}, activity_time = #{activityTime}, categoryId = #{categoryId}, activity_image = #{activityImage} WHERE activityId = #{activityId}")
    Boolean updateActivity(Activity activity);

    //删除活动
    @Delete("DELETE FROM activity WHERE activityId = #{activityId}")
    Boolean deleteActivity(Activity activity);

    /**
     * 查询总记录数
     * @return
     */
    @Select("select count(*) from activity")
    Long count();

    /**
     * 分页查询,获取列表数据
     * @param start
     * @param pageSize
     * @return
     */
    @Select("select * from activity limit #{start},#{pageSize}")
    List<Activity> page(Integer start, Integer pageSize);

    //批量删除
    @Delete({
            "<script>",
            "delete from activity where activityId in",
            "<foreach item='id' collection='ids' open='(' separator=',' close=')'>#{id}</foreach>",
            "</script>"
    })
    Boolean deleteByIds(List<String> ids);

    //查找活动根据id
    @Select("SELECT count(*) FROM activity WHERE activityId = #{activityId}")
    Integer selectByActivityId(String activityId);

}
